package demo;

/**
 * 删除链表中的重复元素
 */
public class Solution42 {
	public ListNode deleteDuplicates(ListNode head) {
		if (head == null || head.next == null) {
			return head;
		}
		ListNode dummy = new ListNode(0);
		dummy.next = head;
		ListNode fast = dummy.next, slow = dummy;
		while (fast != null) {
			if (fast.next != null && fast.val == fast.next.val) {
				while (fast.next != null && fast.val == fast.next.val) {
					fast = fast.next;
				}
				slow.next = fast.next;
			} else {
				slow = slow.next;
			}
			fast = fast.next;
		}
		return dummy.next;
	}
}
